/* 
 * @author Mabel Xu
 */

import info.gridworld.actor.Actor;
import info.gridworld.grid.Grid;
import info.gridworld.grid.Location;
import java.util.ArrayList;

public class ChameleonKid extends ChameleonCritter
{
	public ChameleonKid()
	{
		super();
	}
	
	/**
     * Finds Actors in front and behind this critter.
     * @return a set of Actors that are in front or behind this critter.
     */
	public ArrayList<Actor> getActors()
	{
		ArrayList<Actor> neighbors = new ArrayList<Actor>();
		int[] dirs = {Location.AHEAD, Location.HALF_CIRCLE};
		ArrayList<Location> places = this.getLocationsInDirections(dirs);
		for (Location l : places)
			if (this.getGrid().get(l) != null)
				neighbors.add(this.getGrid().get(l));
		return neighbors;
	}
	
    /**
     * Finds the valid adjacent locations of this critter in different
     * directions.
     * @param directions - an array of directions (which are relative to the
     * current direction)
     * @return a set of valid locations that are neighbors of the current
     * location in the given directions
     */
    public ArrayList<Location> getLocationsInDirections(int[] directions)
    {
        ArrayList<Location> locs = new ArrayList<Location>();
        Grid gr = getGrid();
        Location loc = getLocation();
    
        for (int d : directions)
        {
            Location neighborLoc = loc.getAdjacentLocation(getDirection() + d);
            if (gr.isValid(neighborLoc))
                locs.add(neighborLoc);
        }
        return locs;
    }    
}
